{%extends "admin/base.html" %}

{%block breadcrumb%}
<ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="/admin">首页</a></li>
    <li class="breadcrumb-item"><a href="/admin/system/auth/index">系统权限组管理</a></li>
    <li class="breadcrumb-item active">{{title}}</li>
</ol>
{%endblock%}

{%block main%}
<div class="row">
    <div class="col-12">
        <div class="card">
            <form class="form-horizontal">
                <div class="card-body">
                    <div class="form-group row">
                        <label for="title" class="col-sm-2 col-form-label">
                            权限组名称
                            <span class="text-danger">*</span>
                        </label>
                        <div class="col-sm-10">
                            <input type="input" class="form-control" id="title" name="title" autocomplete="false" {%if info.title %}value="{{info.title}}" {%endif%}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="parameter" class="col-sm-2 col-form-label">描述</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" rows="3" id="describe" name="describe">{%if info.describe %}{{info.describe}}{%endif%}</textarea>
                        </div>
                    </div>
                    {%if info.id > 0%}
                    <input type="hidden" name="id" value="{{info.id}}">
                    {%endif%}
                </div>
                <div class="card-footer">
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
{%endblock%}

{%block js%}
<script>
    $(function () {
        $('form').submit(function (e) {
            e.preventDefault();
            $.post('{{ url("") }}', $('form').serialize(), function (res) {
                _msg = ('msg' in res) ? res.msg : '未知错误';
                if (!('code' in res) || res.code != 0) {
                    toastr.error(_msg);
                } else {
                    toastr.success('保存成功');

                    setTimeout(() => {
                        window.location.href = '{{ url("index") }}';
                    }, 3000);
                }
            });
        });
    });
</script>
{%endblock%}